package com.asas.spaceflight.model;

import com.badlogic.gdx.math.Circle;
import com.badlogic.gdx.math.Polygon;
import com.badlogic.gdx.math.Vector2;

public class PhysicalEntity extends Entity {
	
	public enum FrameType {
		Polygonal, Circular		
	}
	
	private Vector2 position			= new Vector2(0, 0);
	private float height				= 0;
	private float width					= 0;
	private float radius				= 0;
	private float angle					= 0;
	private float mass					= 0;	
	private FrameType frameType			= FrameType.Polygonal;

	private Vector2 acceleration		= new Vector2(0, 0);
	private Vector2 velocity			= new Vector2(0, 0);
	private float angularVelocity		= 0;
	private float maxSpeed				= 0;
	private float maxAngularSpeed		= 0;

	public PhysicalEntity() {
		
	}

	public Vector2 getPosition() {
		return position;
	}

	public void setPosition(Vector2 position) {
		this.position = position;
	}

	public float getHeight() {
		return height;
	}

	public void setHeight(float height) {
		this.height = height;
		this.frameType = FrameType.Polygonal;
	}

	public float getWidth() {
		return width;
	}

	public void setWidth(float width) {
		this.width = width;
		this.frameType = FrameType.Polygonal;
	}

	public float getRadius() {
		return radius;
	}

	public void setRadius(float radius) {
		this.radius = radius;
		this.frameType = FrameType.Circular;
	}

	public float getAngle() {
		return angle;
	}

	public void setAngle(float angle) {
		this.angle = angle;
	}

	public float getMass() {
		return mass;
	}

	public void setMass(float mass) {
		this.mass = mass;
	}

	public Vector2 getVelocity() {
		return velocity;
	}

	public void setVelocity(Vector2 velocity) {
		this.velocity = velocity;
	}

	public Vector2 getAcceleration() {
		return acceleration;
	}

	public void setAcceleration(Vector2 acceleration) {
		this.acceleration = acceleration;
	}

	public float getMaxSpeed() {
		return maxSpeed;
	}

	public void setMaxSpeed(float maxSpeed) {
		this.maxSpeed = maxSpeed;
	}

	public float getAngularSpeed() {
		return maxAngularSpeed;
	}

	public void setAngularSpeed(float angularSpeed) {
		this.maxAngularSpeed = angularSpeed;
	}

	public float getAngularVelocity() {
		return angularVelocity;
	}

	public void setAngularVelocity(float angularVelocity) {
		this.angularVelocity = angularVelocity;
	}

	public FrameType getFrameType() {
		return frameType;
	}

	public void setFrameType(FrameType frameType) {
		this.frameType = frameType;
	}
	
	public Polygon getPolygonalFrame() {
		
		// TODO: Make persistent and calculate only when position or angle changes
		float x = width/2;
		float y = height/2;
		float[] vertices = new float[] {x, y, x, -y, -x, -y, -x, y};
		
		Polygon frame = new Polygon(vertices);
		frame.setPosition(position.x, position.y);
		frame.rotate(angle);
		
		return frame;
	}
	
	public Circle getCircularFrame() {
		
		Circle frame = new Circle();
		frame.set(position.x, position.y, radius);
		return frame;
	}
}
